package com.shenhaofeng.app.component.dialog;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;


/**
 * 警告确认弹窗
 * Created by Administrator on 2016/4/29.
 */
public class AlertDialogFragment extends DialogFragment {


    private CharSequence title;

    private CharSequence message;

    private CharSequence positiveName;

    private DialogInterface.OnClickListener positiveListener;

    private CharSequence negativeName;

    private DialogInterface.OnClickListener negativeListener;


    public AlertDialogFragment() {
    }


    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = new AlertDialog.Builder(getContext())
                .setTitle(title)
                .setMessage(message)
                .setNegativeButton(negativeName, negativeListener)
                .setPositiveButton(positiveName, positiveListener)
                .create();
        return dialog;
    }


    public void setTitle(CharSequence title) {
        this.title = title;
    }


    public void setMessage(CharSequence message) {
        this.message = message;
    }


    public void show(FragmentManager fragmentManager, String tag, CharSequence name, DialogInterface.OnClickListener listener) {
        show(fragmentManager, tag, name, listener, null, null);
    }


    public void show(FragmentManager fragmentManager, String tag, CharSequence positiveName, DialogInterface.OnClickListener positiveListener, CharSequence negativeName, DialogInterface.OnClickListener negativeListener) {
        this.positiveName = positiveName;
        this.positiveListener = positiveListener;
        this.negativeName = negativeName;
        this.negativeListener = negativeListener;
        show(fragmentManager, tag);
    }


}
